package axht.trade.android.listview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class SimpleListViewAdapter extends AppCompatActivity {

    private ListView lv_simple;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simple_list_view_adapter);
        lv_simple = findViewById(R.id.lv_simple);
        List<Map<String, Object>> items = new LinkedList<>();

        TreeMap item = new TreeMap<String,Object>();
        item.put("icon",R.drawable.f1);
        item.put("name","name--1");
        item.put("content","content--1");
        items.add(item);

        item = new TreeMap();
        item.put("icon",R.drawable.f2);
        item.put("name","name--2");
        item.put("content","content--2");
        items.add(item);

        item = new TreeMap();
        item.put("icon",R.drawable.f3);
        item.put("name","name--3");
        item.put("content","content--3");
        items.add(item);


        item = new TreeMap();
        item.put("icon",R.drawable.f4);
        item.put("name","name--4");
        item.put("content","content--4");
        items.add(item);


        item = new TreeMap();
        item.put("icon",R.drawable.f5);
        item.put("name","name--5");
        item.put("content","content--5");
        items.add(item);


        item = new TreeMap();
        item.put("icon",R.drawable.f6);
        item.put("name","name--6");
        item.put("content","content--6");
        items.add(item);


        item = new TreeMap();
        item.put("icon",R.drawable.f7);
        item.put("name","name--7");
        item.put("content","content--7");
        items.add(item);


        item = new TreeMap();
        item.put("icon",R.drawable.f8);
        item.put("name","name--8");
        item.put("content","content--8");
        items.add(item);

        item = new TreeMap();
        item.put("icon",R.drawable.f9);
        item.put("name","name--9");
        item.put("content","content--9");
        items.add(item);

        item = new TreeMap();
        item.put("icon",R.drawable.f10);
        item.put("name","name--10");
        item.put("content","content--10");
        items.add(item);

        String[] from = {"icon","name","content"};

        int[] to = {R.id.iv_item_icon,R.id.tv_item_name,R.id.tv_item_content};

        SimpleAdapter simpleAdapter = new SimpleAdapter(this,items,R.layout.simple_item,from,to);
        lv_simple.setAdapter(simpleAdapter);


    }
}
